package search;

import java.util.ArrayList;
import java.util.Arrays;

public class BinarySearchCycleImpl implements MySearch {
    private int searchCount=0;

    @Override
    public int getSearchCount() {
        return searchCount;
    }
    public static void main(String[] args) {
        //int[] a = {16,52,61,61,88,124,159,561,1024,10001,200000};
        int[] a = {16,22,35,46,52,61,71,88,124,159,201,301};
        //int[] a={88,88,88,88,88,88,88,88,88,88,88,88,88};
        BinarySearchCycleImpl binarySearch = new BinarySearchCycleImpl();
        int result = binarySearch.search(a,16);
        System.out.println("查找结果:"+result);
    }
    @Override
    public int search(int[] array, int value) {
        int left = 0;
        int right=array.length-1;
        while(left<=right){
            int mid = (left+right)/2;
            if(value<array[mid]){
                right=mid-1;
            }else if(value>array[mid]) {
                left=mid+1;
            }else {
                return mid;
            }
        }
        return -1;
    }

    @Override
    public int[] searchs(int[] array, int value) {
        return null;
    }

}
